import bpy
from .data import GROUP_COL, GROUP_OBJ

class UIListItem(bpy.types.PropertyGroup):
    name: bpy.props.StringProperty(default="")

class CG_UI_UIList(bpy.types.UIList):

    def draw_item(self,
                  context: bpy.types.Context,
                  layout: bpy.types.UILayout,
                  data, item, icon, active_data, active_property, index, flt_flag):
        layout = layout.box()
        layout.label(text=item.name)
        row = layout.row(align=True)
        row.label(text=" ")
        box = row.box()
        if item.name == "OBJECT":
            for group in GROUP_OBJ:
                box.label(text=group)
        elif item.name == "COLLECTION":
            for group in GROUP_COL:
                box.label(text=group)


def uilist_reg():
    bpy.utils.register_class(UIListItem)
    bpy.utils.register_class(CG_UI_UIList)

    bpy.types.Scene.cg_item = bpy.props.CollectionProperty(type=UIListItem)
    bpy.types.Scene.cg_item_index = bpy.props.IntProperty(default=0)


def uilist_unreg():
    bpy.utils.unregister_class(UIListItem)
    bpy.utils.unregister_class(CG_UI_UIList)
    del bpy.types.Scene.cg_item
    del bpy.types.Scene.cg_item_index
